IGO8: Use the number of points in the file instead of EOF to to trigger
authorrobertl <robertl>
Wed, 23 Jun 2010 06:22:07 +0000 (06:22 +0000)
committerrobertl <robertl>
Wed, 23 Jun 2010 06:22:07 +0000 (06:22 +0000)
completion.

igo8.c

diff --git a/igo8.c b/igo8.c
index 9698f2d537453a2da6b0725b5b285c92abaca937..6bbcd4483ff65b84a38d6e151fb5693c9574f3c5 100644 (file)
--- a/igo8.c
+++ b/igo8.c
@@ -104,8 +104,9 @@ static char* igo8_option_title = NULL;
 static char* igo8_option_description = NULL;
 
 // Internal state
-gbuint32 invented_time;
-gbuint32 point_count;
+static gbuint32 invented_time;
+static gbuint32 point_count;
+static int in_point_count;
 
 // Exported options list
 static arglist_t igo8_options[] = {
@@ -145,8 +146,12 @@ static void igo8_read_init(const char *fname)
        // Make sure that we are in the environment we expect and require
        igo8_check_type_sizes();
 
-       // Seek past the header and the Information Block
-       gbfseek(igo8_file_in, IGO8_HEADER_SIZE + sizeof(igo8_information_block), SEEK_SET);
+       // Seek past the header and most of the Information Block.  Read
+       // the last word for trackpoint count since latest igo8 seems to 
+       // zero-pad the files.
+       gbfseek(igo8_file_in, IGO8_HEADER_SIZE + sizeof(igo8_information_block) - 4, SEEK_SET);
+       in_point_count = (gbfgetint32(igo8_file_in) - IGO8_HEADER_SIZE -
+               sizeof(igo8_information_block)) / sizeof(igo8_point);
 }
 
 // Reader callback
@@ -159,7 +164,9 @@ static void igo8_read(void)
        track_head = route_head_alloc();
        track_add_head(track_head);
 
-       while (gbfread(&point, sizeof(point), 1, igo8_file_in) > 0) {
+       while (in_point_count &&
+                       gbfread(&point, sizeof(point), 1, igo8_file_in) > 0) {
+               in_point_count--;
                wpt_tmp = waypt_new();
 
                wpt_tmp->latitude = le_read32(&point.lat) / (double)0x800000;